<template>
  <!-- Bu总 费用管理列表  -->
  <view class="costs-assign">
    <div :class="['costs-assign-item orange']" v-for="(item, index) in List" :key="index">
      <div class="costs-assign-item-title">
        <div class="title nowrap">{{ item.CompanyName }}</div>
        <div class="timer nowrap">{{ item.Year }}年 {{ QuarterMap[item.QuarterId] }}</div>
      </div>
      <div class="costs-assign-item-con">
        <div class="row-item">
          <div class="u-flex">
            <div class="label-name">本季度金额：</div>
            <div class="price">￥{{ item.TotalCost }}</div>
          </div>
          <!--      <div class="edit-text">修改费用></div> -->
        </div>
        <div class="row-item">
          <div class="u-flex">
            <div class="label-name">费用总金额：</div>
            <div class="price">￥{{ item.ToCost }}</div>
          </div>
        </div>
        <div class="row-item">
          <div class="u-flex">
            <div class="label-name">剩余金额：</div>
            <div class="price">￥{{ getBalanceMoney(item) }}</div>
          </div>
        </div>
        <div v-if="item.Level == 1" class="btn-group u-m-t-20 u-text-right u-p-b-20 u-p-r-20">
          <u-button
            class=" u-m-l-30"
            type="warning"
            size="medium"
            :custom-style="btnStyle"
            shape="circle"
            plain
            @click="$u.route({ url: '/pages/marketCosts/bu/detail', params: { Id: item.Id } })"
          >
            详情
          </u-button>

          <u-button
            class=" u-m-l-30"
            type="warning"
            size="medium"
            :custom-style="btnStyle"
            shape="circle"
            @click="toAssignPage(item)"
          >
            费用分配
          </u-button>
        </div>
      </div>
    </div>
  </view>
</template>

<script>
export default {
  data() {
    return {
      isShowBtn: false,

      btnStyle: {
        height: '50rpx',
        color: '#ffffff',
        padding: '0 30rpx'
      },

      QuarterMap: {
        '1': '第一季度',
        '2': '第二季度',
        '3': '第三季度',
        '4': '第四季度'
      },

      IsFirst: true,
      Page: {
        Items: [],
        PageCount: 0,
        PageIndex: 0,
        PageSize: 10,
        TotalCount: 0
      },
      List: [],

      searchParams: {
        Year: '',
        QuarterId: '',
        CompanyId: ''
      },
      status: 'loadmore'
    };
  },

  onLoad() {
    this.getData();
  },

  methods: {
    getBalanceMoney(item) {
      return Number(item.ToCost) - Number(item.BDRCost) + (Number(item.BDRCost) - Number(item.CheckCost));
    },

    // 当前年 并且 当前季度才显示的操作
    showActions(item) {
      let now = new Date();
      let year = now.getFullYear();
      let month = now.getMonth();
      let quarter = parseInt((month + 3) / 3);

      return year == item.Year && quarter == item.QuarterId && item.Level == 1;
    },

    toAssignPage(item) {
      this.$u.route({
        url: '/pages/marketCosts/bu/costsAssign',
        params: {
          Id: item.Id
        }
      });
    },

    getData(reload) {
      this.$u.api
        .getBuCostsPage({
          ...this.searchParams,
          ...{
            Pageindex: this.Page.PageIndex,
            Pagesize: this.Page.PageSize
          }
        })
        .then(res => {
          const { MarketMoney_Set_List: PageList, ResultCode, ResultMessage } = res;

          if (ResultCode == 1) {
            if (PageList) {
              this.Page = PageList;
              if (reload) {
                this.List = PageList.Items;
              } else {
                this.List.push(...PageList.Items);
              }

              if (this.Page.PageIndex + 1 >= this.Page.PageCount) {
                this.status = 'nomore';
              }
            } else {
              this.List = [];
              this.status = 'nomore';
            }
          } else {
            this.$u.toast(ResultMessage);
          }
        });
    }
  }
};
</script>

<style lang="scss">
.costs-assign {
  width: 750rpx;
  padding: 20rpx 20rpx;
  .costs-assign-item {
    border-top: 6rpx solid #ff8441;
    position: relative;
    box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.3);
    border-radius: 16rpx;
    margin-bottom: 28rpx;
    .costs-assign-item-title {
      border-radius: 16rpx 16rpx 0 0;
      line-height: 90rpx;
      font-size: 30rpx;
      color: #ff7626;
      border-bottom: 1px solid #ccc;
      display: flex;
      .title {
        margin-left: 20rpx;
        flex: 2;
        font-size: 36rpx;
        font-weight: bold;
      }
      .timer {
        margin-left: 26rpx;
        flex: 1;
        font-size: 28rpx;
      }
    }
    .costs-assign-item-con {
      font-size: 30rpx;
      padding: 10rpx 20rpx 20rpx 20rpx;
      .row-item {
        display: flex;
        margin-top: 16rpx;
        justify-content: space-between;
        .label-name {
          color: #979797;
          width: 200rpx;
        }
        .edit-text {
          color: #ff7626;
          margin-left: 40rpx;
        }
      }
    }
    .btn-wrap {
      margin-top: 20rpx;
      display: flex;
      align-items: center;
      justify-content: flex-end;
      .btn-item {
        margin-left: 20rpx;
        border-radius: 6rpx;
        padding: 10rpx 0;
        width: 160rpx;
        text-align: center;
      }
      .info-btn,
      .set-btn,
      .adjust-btn {
        border: 1px solid #ff7626;
        color: #ff7626;
      }
      .cost-btn {
        border: 1px solid #f7b66e;
        background: linear-gradient(301.09deg, #f29e40 6.64%, #f7b66e 91.7%);
        color: #fff;
      }
    }
  }
}

.nowrap {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
</style>
